import path from 'path'
import i18n from '@/i18n'
export function getData(routes, basePath = '/', preTitle = []) {
  const result = []
  for (const item of routes) {
    const data = {
      path: path.resolve(basePath, item.path),
      title: [...preTitle]
    }
    if (item.meta && item.meta.title && !item.path.includes(':')) {
      const i18nTitle = i18n.global.t(`message.route.${item.meta.title}`)
      data.title.push(i18nTitle)
      result.push(data)
    }
    if (item.children && item.children.length > 0) {
      const children = getData(item.children, data.path, data.title)
      if (children.length > 1) {
        result.push(...children)
      }
    }
  }
  return result
}
